package ywpt.service.people;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;

import ywpt.core.dao.HibernateEntityDao;
import ywpt.model.CommonTable;
import ywpt.model.PeopleApplyInfo;
import ywpt.model.PeopleInfo;
import ywpt.model.PositionInfo;

public class PeopleApplyInfoServiceImpl extends HibernateEntityDao<PeopleApplyInfo> implements PeopleApplyInfoService{
	@Override
	public PeopleApplyInfo getPeopleApplyInfoById(Long id) {
		return this.get(id);
	}

	@Override
	public int getPeopleApplyInfoCountByCriteria(DetachedCriteria query) {
		return this.getCountByCriteria(query);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<PeopleApplyInfo> getPeopleApplyInfos(DetachedCriteria query,
			int pageSize, int startIndex) {
		return this.findAllByCriteria(query, pageSize, startIndex);
	}

	@Override
	public void savePeopleApplyInfo(PeopleApplyInfo peopleApplyInfo,
			Long applyId, Long typeId, Long positionId, Long checkerId) {
		if (applyId!=null) {
			peopleApplyInfo.setApplyUser(this.get(PeopleInfo.class, applyId));
		}
		if (typeId!=null) {
			peopleApplyInfo.setApplyType(this.get(CommonTable.class, typeId))	;
		}
		if (positionId!=null) {
			peopleApplyInfo.setPosition(this.get(PositionInfo.class, positionId));
		}
		if (checkerId!=null) {
			peopleApplyInfo.setChecker(this.get(PeopleInfo.class, checkerId));
		}
		this.save(peopleApplyInfo);	
	}

	@Override
	public void updatePeopleApplyInfo(PeopleApplyInfo peopleApplyInfo,
			Long applyId, Long typeId, Long positionId, Long checkerId) {
		if (applyId!=null) {
			peopleApplyInfo.setApplyUser(this.get(PeopleInfo.class, applyId));
		}
		if (typeId!=null) {
			peopleApplyInfo.setApplyType(this.get(CommonTable.class, typeId))	;
		}
		if (positionId!=null) {
			peopleApplyInfo.setPosition(this.get(PositionInfo.class, positionId));
		}
		if (checkerId!=null) {
			peopleApplyInfo.setChecker(this.get(PeopleInfo.class, checkerId));
		}
		this.update(peopleApplyInfo);
	}
	


}
